﻿@using Nop.Plugin.Misc.RFQ.Models.Admin
@model QuoteModel

@{
    var title = string.Format(T("Plugins.Misc.RFQ.QuoteNumber").Text, Model.Id);

    Layout = "_AdminLayout";
    //page title
    ViewBag.PageTitle = title;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName(RfqDefaults.QuotesAdminMenuSystemName);

    const string hideInfoBlockAttributeName = "AdminQuote.HideInfoBlock";
    var customer = await workContext.GetCurrentCustomerAsync();
    var hideInfoBlock = await genericAttributeService.GetAttributeAsync<bool>(customer, hideInfoBlockAttributeName);
}

<div asp-validation-summary="All"></div>

<form asp-controller="RfqAdmin" asp-action="AdminQuote" method="post">
    <input asp-for="Id" type="hidden" />
    <div class="content-header clearfix">
        <h1 class="float-left">
            @title
            <small>
                <i class="fas fa-arrow-circle-left"></i>
                <a asp-action="AdminQuotes">@T("Plugins.Misc.RFQ.AdminQuote.BackToList")</a>
            </small>
        </h1>
        <div class="float-right">
            @if (Model.DisplayAddNewProductButton)
            {
                <button type="submit" id="btnAddNewProduct" name="btnAddNewProduct" onclick="javascript:setLocation('@(Url.Action("AddProductToQuote", "RfqAdmin", new { quoteId = Model.Id }))'); return false;" class="btn btn-info">
                    <i class="far fa-plus-square"></i>
                    @T("Plugins.Misc.RFQ.AddNewProduct")
                </button>
            }
            @if (Model.DisplaySendQuoteButton)
            {
                <button type="submit"
                        name="sendQuote"
                        id="send-request"
                        class="btn btn-info">
                    <i class="far fa-share-square"></i>
                    @T("Plugins.Misc.RFQ.SendQuote")
                </button>
            }
            @if (Model.Items.Any())
            {
                <a asp-action="PdfDocument" asp-controller="RfqAdmin" asp-route-quoteId="@Model.Id" class="btn btn-info">
                    <i class="far fa-file-pdf"></i>
                    @T("Plugins.Misc.RFQ.CreatePdf")
                </a>
            }
            @if (Model.DisplayDeleteQuoteButton)
            {
                <button type="submit"
                        id="delete-quote"
                        name="deleteQuote"
                        class="btn btn-danger">
                    <i class="far fa-trash-alt"></i>
                    @T("Admin.Common.Delete")
                </button>
            }
            @if (Model.DisplaySaveButtons)
            {
                <button type="submit" name="save" class="btn btn-primary">
                    <i class="far fa-save"></i>
                    @T("Admin.Common.Save")
                </button>
                <button type="submit" name="save-continue" class="btn btn-primary">
                    <i class="far fa-save"></i>
                    @T("Admin.Common.SaveContinue")
                </button>
            }
        </div>
    </div>
    <section class="content">
        <div class="container-fluid">
            <div class="form-horizontal">
                <nop-cards id="quote-cards">
                    <nop-card asp-name="quote-info" asp-icon="fas fa-info" asp-title="@T("Plugins.Misc.RFQ.CustomerQuote.Info")" asp-hide-block-attribute-name="@hideInfoBlockAttributeName" asp-hide="@hideInfoBlock" asp-advanced="false">
                        <div class="card-body">
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="CustomerEmail" />
                                </div>
                                <div class="col-md-9">
                                    <div class="form-text-row">
                                        <a asp-controller="Customer" asp-action="Edit" asp-route-id="@Model.CustomerId">@(!string.IsNullOrEmpty(Model.CustomerEmail) ? Model.CustomerEmail : T("Admin.Customers.Guest").Text)</a>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="CreatedOn" />
                                </div>
                                <div class="col-md-9">
                                    <div class="form-text-row">@Model.CreatedOn</div>
                                </div>
                            </div>
                            @if (Model.Editable || Model.ExpirationDateUtc.HasValue)
                            {
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="ExpirationDateUtc" />
                                    </div>
                                    @if (Model.Editable)
                                    {
                                        <div class="col-md-9">
                                            <nop-editor asp-for="ExpirationDateUtc" />
                                        </div>
                                    }
                                    else
                                    {
                                        <div class="col-md-9">
                                            <div class="form-text-row">@Model.ExpirationDateUtc</div>
                                        </div>
                                    }
                                </div>
                            }
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="Status" />
                                </div>
                                <div class="col-md-9">
                                    <div class="form-text-row">@Model.Status</div>
                                </div>
                            </div>
                            @if (Model.RequestQuoteId.HasValue)
                            {
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="RequestQuoteId" />
                                    </div>
                                    <div class="col-md-9">
                                        <div class="form-text-row"><a href="~/Admin/RfqAdmin/AdminRequest/@Model.RequestQuoteId.Value">#@Model.RequestQuoteId.Value</a></div>
                                    </div>
                                </div>
                            }
                            @if (Model.OrderId.HasValue)
                            {
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="OrderId" />
                                    </div>
                                    <div class="col-md-9">
                                        <div class="form-text-row"><a href="~/Admin/Order/Edit/@Model.OrderId.Value">#@Model.OrderId.Value</a></div>
                                    </div>
                                </div>
                            }
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="AdminNotes" />
                                </div>
                                <div class="col-md-9">
                                    @if (Model.Editable)
                                    {
                                        <nop-textarea asp-for="AdminNotes"></nop-textarea>
                                    }
                                    else
                                    {
                                        <div class="form-text-row">
                                            @Html.Raw(Model.AdminNotes.Replace(Environment.NewLine, "<br />"))
                                        </div>
                                    }
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-12">
                                    <h3>@T("Plugins.Misc.RFQ.Products")</h3>
                                    @await Html.PartialAsync("_AdminQuote.Products.cshtml", Model)
                                </div>
                            </div>
                        </div>
                    </nop-card>
                </nop-cards>
            </div>
        </div>
    </section>
</form>

<nop-action-confirmation asp-button-id="send-request" />
<nop-action-confirmation asp-button-id="delete-quote" />

